var vm=new Vue({
    el:"#consult",
    data: {
        departmentList:[],
        consult:{
            department:"",
            doctor:"",
            username:"",
            sex:"",
            birthday:"",
            location:"",
            consuitAim:"",
            details:{
                onsetExperience:{startTime:"",complicationTime:"",consultAim:""},
                medicalHistory:{disease:"",treatmentHospital:"",treatment:"",doctor:""}
            }
        },
        doctorList:[],
        doctor:{}
    },
    created () {
        this.selectDepartment();
        this.getPageData();
        this.selectByDepartment();
        Object.assign(this.$data, this.$options.data())
    },
    methods: {
        /*显示所有科室*/
        selectDepartment:function (){
            let that=this;
            axios.get("/department/selectDepartment.do").then(function (response){
                that.departmentList=response.data;department/selectDepartment.d
            }).catch(function (error) {
                console.log(error);
            });
        },
        //根据科室显示所有医生信息
        selectByDepartment:function (){
            let that=this;
            axios.get("/doctor/selectByDepartment.do?department="+this.consult.department).then(function (response){
                that.doctorList=response.data;
            }).catch(function (error) {
                console.log(error);
            });
        },
        //根据指定索引查看医生详情信息
        findId:function (i) {
            this.doctor = this.doctorList[i];
            localStorage.setItem('this.doctor',JSON.stringify(this.doctor));
        },

        //点击下一页保存数据
        nextSave:function (){
            localStorage.setItem('this.consult',JSON.stringify(this.consult));
        },
        //刷新页面或者从别的页面进入，提取this.consult的值
        getPageData:function(){
                this.consult = JSON.parse(localStorage.getItem('this.consult'));//使用getItem方法的前提是，你再自己需要的地方使用了setItem方法
            this.doctor = JSON.parse(localStorage.getItem('this.doctor'));
            if(this.consult==null){
                this.consult={
                    department:"",
                    doctor:"",
                    username:"",
                    sex:"",
                    birthday:"",
                    location:"",
                    consuitAim:"",
                    details:{
                        onsetExperience:{startTime:"",complicationTime:"",consultAim:""},
                        medicalHistory:{disease:"",treatmentHospital:"",treatment:"",doctor:""}
                    }
                }
            }
            if(this.doctor==null){
                this.doctor={}
            }
        },
        //添加订单到数据库
        insert:function (){
            let temp=JSON.parse(JSON.stringify(this.consult));
            temp.details=JSON.stringify(temp.details);
            axios.post("/consult/insert.do",temp).then(function (response){
                if (response.data.success){
                    localStorage.clear();
                    window.location.href='/会诊医生_支付成功.html';
                }else {
                    alert(response.data.message)
                }
            })
        }

    }

})